//
//  PKDiscoveryViewController.swift
//  Panku
//
//  Created by mac on 2017/2/6.
//  Copyright © 2017年 Monster. All rights reserved.
//

import UIKit
import YYKit
import SnapKit
import MJRefresh

//Cell ID
private let PKDiscoveryControllerListCellID = "PKDiscoveryControllerListCellID"

class PKDiscoveryViewController: PKBaseViewController,UITableViewDataSource,UITableViewDelegate {
    
    
    //MARK: - init
    init(viewModel:PKDiscoveryViewModel) {
        self.viewModel = viewModel
        super.init(nibName: nil, bundle: nil)
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    //MARK: - properties
    lazy var tableView = PKBaseTableView { (make) in
        
    }
    
    //viewModel
    var viewModel:PKDiscoveryViewModel?

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
    }

    
    //MARK: - setupUI
    override func setupRootView() {
        
        
    }
    
    override func setupSubViews() {
        view.addSubview(tableView)
        
        tableView.delegate = self
        tableView.dataSource = self
        tableView.register(PKDiscoveryControllerListCell.self, forCellReuseIdentifier: PKDiscoveryControllerListCellID)
        
        tableView.mj_header = MJRefreshNormalHeader(refreshingBlock: {
            print("我被下拉刷新啦")
            self.tableView.mj_header.endRefreshing()
        })
    }
    
    override func setupSubViewsConstraints() {
        tableView.snp.makeConstraints { (make) in
            make.edges.equalTo(view)
        }
    }
    
    override func setupNavigationBar() {
        
    }
    
    override func bindViewModel() {
        
    }

    



}

extension PKDiscoveryViewController{
    
    func numberOfSections(in tableView: UITableView) -> Int {
         return viewModel!.numberOfSection()
    }
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
         return viewModel!.numberOfRowsInSection()
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: PKDiscoveryControllerListCellID, for: indexPath)
        
        return cell
    }
    
    func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
        
    }
    
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        return viewModel!.heightForRowAt(index: indexPath.row)
    }
}
